<template>
  <div class="hotlist">
    <h2>热门歌单</h2>
    <div class="textList">
      <span v-for="(item, index) in textList" :key="index" @click="queryList(item.id, index, item.name)"
        :class="textListIndex == index ? 'active' : ''">{{ item.name }}</span>
    </div>
    <div class="hotlistContent">
      <div class="contentList" v-for="(item, index) in contentList" :key="index">
        <img :src="item.coverImgUrl + '?param=180y180'" @click="detail(item.id)" />
        <span @click="detail(item.id)">{{ "#" + item.name }}</span>
      </div>
    </div>
  </div>
</template>

<script>
import { hostList, topList } from "@/api/api";
export default {
  name: "hotlist",
  data() {
    return {
      textList: [],
      contentList: [],
      textListIndex: 0,
      contentParams: { limit: 5, cat: "全部", },
      params: { keywords: '' }
    };
  },
  mounted() {
    this.getList(this.contentParams);
  },
  methods: {
    getList(params) {
      hostList().then((res) => {
        res.data.tags.unshift({ name: "全部" });
        this.textList = res.data.tags.splice(0, 6); //  取数组的前六个
      });
      topList(params).then((res) => {
        this.contentList = res.data.playlists;
      });
    },
    queryList(id, index, name) {
      this.textListIndex = index;
      this.contentParams.cat = name
      this.getList(this.contentParams);

    },
    detail(id) {
      this.$router.push({ path: "/songdetails", query: { detailId: id } })
    },
  },
};
</script>

<style lang='less' scoped>
.hotlist {
  width: 1200px;
  margin-top: 20px;

  h2 {
    font-family: "hmB";
    font-size: 28px;
    color: rgb(68, 68, 68);
    text-align: center;
    margin-bottom: 20px;
  }

  .textList {
    width: 300px;
    display: flex;
    margin: 0 auto 20px auto;
    justify-content: space-between;

    span {
      display: inline-block;
      text-align: center;
      font-family: "hmR";
      font-size: 16px;
      color: #6b6b6b;
      cursor: pointer;
    }

    .active {
      border-bottom: 3px solid rgb(61, 116, 240);
    }
  }

  .hotlistContent {
    width: 1200px;
    height: auto;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;

    .contentList {
      width: 180px;
      height: 180px;
      cursor: pointer;

      img {
        width: 180px;
        height: 180px;
        transition: all 0.2s linear;
        border-radius: 5px;
        overflow: hidden;
      }

      img:hover {
        transform: scale(1.05, 1.05);
        transition: all 0.2s linear;
      }

      span {
        margin-top: 5px;
        display: inline-block;
        width: 180px;
        height: 30px;
        font-size: 14px;
        font-family: "hmR";
        color: rgb(61, 116, 240);
        word-break: break-all;
        word-wrap: break-word;
        overflow: hidden;
        line-height: 15px;
        text-overflow: ellipsis;
        display: -webkit-box;
        /*重新定义-webkit私有盒模型*/
        -webkit-box-orient: vertical;
        /*内容之间的排列顺序，vertical垂直方向排列*/
        -webkit-line-clamp: 2;
        /*在第几行末尾显示省略号...*/
        word-break: break-all;
        cursor: pointer;
      }
    }

    .contentText {
      vertical-align: top;
      margin-top: 5px;
      width: 180px;
      word-break: break-all;
      word-wrap: break-word;
      height: auto;
      font-family: "hmR";
      font-size: 16px;
      color: #6b6b6b;
    }
  }
}
</style>